﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.Mvc;
using borkoSi.Models;
using borkoSi.ViewModels;

namespace borkoSi.Controllers
{
    public class CyclingController : Controller
    {

        private borkoSiEntities db = new borkoSiEntities();

        //
        // GET: /Cycling/

        public ActionResult Index()
        {
            CyclingViewModel model = new CyclingViewModel();

            model.RoutesDropdownItems = db.Cyclings.OrderByDescending(r => r.RouteId).ToList()
                                            .Select(r => new SelectListItem
                                                {
                                                    Value = r.RouteId.ToString(),
                                                    Text = r.RouteId + " - " + r.RouteName
                                                });

            return View(model);
        }

        //
        // GET: /Cycling/Route

        public ActionResult Route(int id = 1)
        {
            Cycling model = new Cycling();

            model.RouteName = db.Cyclings.Find(id).RouteName.ToString();
            
            model.Url = WebConfigurationManager.AppSettings["GarminUrlForRouteEmbed"].ToString() +
                        db.Cyclings.Find(id).RouteNumber;

            return View(model);
        }

        //
        // GET: /Cycling/GetGarminIframeSource?id

        public ActionResult GetGarminIframeSource(int id = 1) {
            
            string src = WebConfigurationManager.AppSettings["GarminUrlForRouteEmbed"].ToString() +
                            db.Cyclings.Find(id).RouteNumber;

            return Content(src);
        }

    }
}
